package com.xinqi.modules.sys.sensitive.word.factory;

import com.xinqi.common.base.error.CommonErrors;
import com.xinqi.common.base.response.PageInfo;
import com.xinqi.common.base.response.R;
import com.xinqi.modules.sys.sensitive.word.client.SensitiveWordClient;
import com.xinqi.modules.sys.sensitive.word.dto.req.SensitiveWordQueryDTO;
import com.xinqi.modules.sys.sensitive.word.dto.rsp.SensitiveWordResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cloud.openfeign.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * 敏感词管理表降级处理
 *
 * @author: wenjie
 * @date: 2023/08/02
 */
@Slf4j
@Component
public class SensitiveWordFallbackFactory implements FallbackFactory<SensitiveWordClient> {

    @Override
    public SensitiveWordClient create(Throwable throwable) {
        log.error("日志服务调用失败:{}", throwable.getMessage());
        return new SensitiveWordClient() {
            @Override
            public R<PageInfo<SensitiveWordResultDTO>> page(SensitiveWordQueryDTO dto) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }

            @Override
            public R<SensitiveWordResultDTO> findById(Long id) {
                return R.error(CommonErrors.INTERNAL_SERVER_ERROR.getCode(), null);
            }
        };
    }
}
